<template>
    <div class="riks-query"> 
        <div class="tags">
            <div 
            class="info-type"
            v-for="(item,ind) in navs" 
            :key="ind"
            v-czc="['查企业-详情-基本信息', '导航' , item.nodeName, 0 ,`checkEnterpriseInfo-btn-${item.nodeid}`]"
            >
                <el-button 
                size="mini" 
                plain
                :type="!btnDisabled(item) ? '' : 'info'"
                :disabled="btnDisabled(item)"
                @click="go(item)"
                >
                    {{item.nodeName || item.itemName}}
                </el-button>
            </div>
        </div>

        <template v-if="isLogin">
            <div class="riks-main" v-if="isHavingPower">

                <div 
                class="item" 
                v-for="(item,ind) in navs" :key="ind"
                >
                    <div v-if="item.nodeId" :id="item.nodeId">
                        <h3 v-show="isValid(item)">{{item.nodeName}}</h3>
                        
                        <component 
                            ref="comRef" 
                            :is="componentName(item.nodeId)" 
                            v-show="isLogin && isValid(item)"
                            :nodeId="item.nodeId" 
                            :navName="item.nodeName"
                            :companyName="company"
                            :taxNumber="taxNumber"
                            :corpType="corpType"
                            :jiaotongComId="jiaotongComId"
                            :shuiliComId="shuiliComId"
                            @pushValidNames="pushValidNames"
                        ></component>
                    </div>

                    <div v-else>
                        <div 
                        v-for="(child,ind1) in item.itemNodeRecords" 
                        :key="ind1" 
                        :id="child.nodeId"
                        >
                            <h3 v-show="isValid(item)">{{child.nodeName}}</h3>

                            <component 
                                ref="comRef" 
                                :is="componentName(child.nodeId)" 
                                v-show="isLogin && isValid(item)"
                                :nodeId="child.nodeId"
                                :navName="child.itemName" 
                                :companyName="company"
                                :taxNumber="taxNumber"
                                :corpType="corpType"
                                :jiaotongComId="jiaotongComId"
                                :shuiliComId="shuiliComId"
                                @pushValidNames="pushValidNames"
                            ></component>
                        </div>
                    </div>
                </div>

            </div>
        </template>

        <shade
            class="guide" 
            id="guide" 
            type="business"
            :surplusNum="surplusNum"
            imgType="business2"
            :isHavingPower="isHavingPower" 
            :isLogin="isLogin" 
            @use="$emit('use')" 
            @afterBuy="$emit('afterBuy')" 
        ></shade>
    </div> 
</template>

<script>
import componentsNameById from '../mixins/components-name'

import guojiaQiye from '../search/tiany/guojiaqiye.vue' 
import jtQiyeInfo from '../search/jiaotong/qiyeinfo'
import jtZiZhi from '../search/jiaotong/zizhi'
import jtYeJi from '../search/jiaotong/yeji'
import jtRenYuan from '../search/jiaotong/renyuan'
import jtPingJia from '../search/jiaotong/pingjia'


import slQiyeInfo from '../search/shuili/qiyeinfo'
import slBuliang from '../search/shuili/buliang'
import slLianghao from '../search/shuili/lianghao'
import slXinYong from '../search/shuili/xinyong'
import slYeJi from '../search/shuili/yeji'
import slRenYuan from '../search/shuili/renyuan'
import slZiZhi from '../search/shuili/zizhi'
import skBuliang from '../search/tiany/buliang'
import skRenyuan from '../search/tiany/renyuan'
import skYeji from '../search/tiany/yeji'
import skZizhi from '../search/tiany/zizhi'
import caipanFalv from '../search/tiany/falv'
import zhengcaiShixin from '../search/tiany/shixin'
import hmdXizang from '../search/hmd/xizang'
import hmdShandong from '../search/hmd/shandong'
import hmdZhonghua from '../search/hmd/zhonghua'
import hmdHubei from '../search/hmd/hubei'
import hmdGuangxi from '../search/hmd/guangxi'
import tuoqianSiku from '../search/tuoqian/siku'
import tuoqianJzgr from '../search/tuoqian/jzgr'
import tuoqianZhonghua from '../search/tuoqian/zhonghua'
import sichuanChengxin from '../search/sichuan/chengxin'
import fujianXinyong from '../search/fujian/xinyong'
import zhongdaShuishou from '../search/xinyong/zhongdashuishou'
import shixinBeizhixing from '../search/xinyong/shixinbeizhixing'
import changyongCaipan from '../search/changyong/caipan.vue'
import changyongJundui from '../search/changyong/jundui.vue' 
import changyongShuiwu from '../search/changyong/shuiwu.vue'

import shade from '../../../components/shade.vue'

export default {
    mixins: [ componentsNameById ],
    components: {
        guojiaQiye,
        jtQiyeInfo,
        jtZiZhi,
        jtYeJi,
        jtRenYuan,
        jtPingJia,
        slQiyeInfo,
        slBuliang,
        slLianghao,
        slYeJi,
        slXinYong,
        slRenYuan,
        slZiZhi,
        skBuliang,
        skRenyuan,
        skZizhi,
        skYeji,
        caipanFalv,
        zhengcaiShixin,
        hmdXizang,
        hmdShandong,
        tuoqianSiku,
        tuoqianJzgr,
        hmdZhonghua,
        hmdHubei,
        hmdGuangxi,
        sichuanChengxin,
        tuoqianZhonghua,
        fujianXinyong,
        zhongdaShuishou,
        shixinBeizhixing,
        changyongCaipan,
        changyongJundui,
        changyongShuiwu,
        shade,
    },
    props: {
        isHavingPower: {
            type: Boolean,
            default: false
        },
        isLogin: {
            type: Boolean,
            default: false,
        },
        surplusNum: {
            type: Number,
            default: 0
        },
        company:{
            type: String,
            default: ''
        }
    },
    data() {
        return {
            radio:"0",
        //    company:'中启建设有限公司',//查询企业名称,
            taxNumber:"915100005826187158",//信用代码
            jiaotongComId:'', //交通
            shuiliComId:'', //水利
            corpType:'',
            validNames:[],

            navs: [
                {
                    'itemId': '100', 
                    'itemName': '常用查询', 
                    'nodeId': '101', 
                    'nodeName': '严重违法企业名单',
                    'nodeid':'yzwfqymd',
                }, 
                {
                    'itemId': '100', 
                    'itemName': '常用查询', 
                    'nodeId': '103', 
                    'nodeName': '失信被执行人',
                    'nodeid':'sxbzxrmd',
                }, 
                {
                    'itemId': '100', 
                    'itemName': '常用查询', 
                    'nodeId': '104', 
                    'nodeName': '行贿犯罪记录',
                    'nodeid':'hhfzjl',
                }, 
                {
                    'itemId': '100', 
                    'itemName': '常用查询', 
                    'nodeId': '105', 
                    'nodeName': '黑名单',
                    'nodeid':'hmd',
                }, 
                {
                    'itemId': '100', 
                    'itemName': '常用查询', 
                    'nodeId': '106', 
                    'nodeName': '严重违法记录' ,
                    'nodeid':'zzwfjl',
                }, 
                {
                    'itemId': '100', 
                    'itemName': '常用查询', 
                    'nodeId': '107', 
                    'nodeName': '重大税务违法',
                    'nodeid':'zdswwf',
                },

                {
                    'itemId': '4', 
                    'itemName': '全国公路建设市场信用信息管理系统', 
                    'itemNodeRecords': [
                        {
                            'itemId': '4', 
                            'itemName': '全国公路建设市场信用信息管理系统', 
                            'nodeId': '15', 
                            'nodeName': '公路-企业信息'
                        }, 
                        { 
                            'itemId': '4', 
                            'itemName': '全国公路建设市场信用信息管理系统', 
                            'nodeId': '19', 
                            'nodeName': '公路-信用评价'
                        }, 
                        {
                            'itemId': '4', 
                            'itemName': '全国公路建设市场信用信息管理系统', 
                            'nodeId': '18', 
                            'nodeName': '公路-人员'
                        }, 
                        {
                            'itemId': '4', 
                            'itemName': '全国公路建设市场信用信息管理系统', 
                            'nodeId': '17', 
                            'nodeName': '公路-业绩'
                        }, 
                        { 
                            'itemId': '4', 
                            'itemName': '全国公路建设市场信用信息管理系统', 
                            'nodeId': '16', 
                            'nodeName': '公路-资质信息'
                        }
                    ], 
                    'remark': null,
                    'nodeid':'gljsglxt',
                }, 
                // {
                //     'itemId': '3', 
                //     'itemName': '全国水利建设市场信用信息平台', 
                //     'itemNodeRecords': [
                //         {
                //             'itemId': '3', 
                //             'itemName': '全国水利建设市场信用信息平台', 
                //             'nodeId': '8', 
                //             'nodeName': '水利-企业信息' 
                //         }, 
                //         {
                //             'itemId': '3', 
                //             'itemName': '全国水利建设市场信用信息平台', 
                //             'nodeId': '14', 
                //             'nodeName': '水利-不良行为' 
                //         }, 
                //         {
                //             'itemId': '3', 
                //             'itemName': '全国水利建设市场信用信息平台', 
                //             'nodeId': '13', 
                //             'nodeName': '水利-良好行为' 
                //         }, 
                //         {
                //             'itemId': '3', 
                //             'itemName': '全国水利建设市场信用信息平台', 
                //             'nodeId': '12', 
                //             'nodeName': '水利-信用评价'
                //         }, 
                //         { 
                //             'itemId': '3', 
                //             'itemName': '全国水利建设市场信用信息平台', 
                //             'nodeId': '11', 
                //             'nodeName': '水利-工程业绩'
                //         }, 
                //         {
                //             'itemId': '3', 
                //             'itemName': '全国水利建设市场信用信息平台', 
                //             'nodeId': '10', 
                //             'nodeName': '水利-人员信息'
                //         }, 
                //         {
                //             'itemId': '3', 
                //             'itemName': '全国水利建设市场信用信息平台', 
                //             'nodeId': '9', 
                //             'nodeName': '水利-资质信息'
                //         }
                //     ], 
                //     'remark': null,
                //     'nodeid':'sljspt',
                // }, 
                {
                    'itemId': '1', 
                    'itemName': '四库一平台', 
                    'itemNodeRecords': [
                        { 
                            'itemId': '1', 
                            'itemName': '四库一平台', 
                            'nodeId': '3', 
                            'nodeName': '建筑-人员'
                        }, 
                        { 
                            'itemId': '1', 
                            'itemName': '四库一平台', 
                            'nodeId': '1', 
                            'nodeName': '建筑-资质证书'
                        }, 
                        {
                            'itemId': '1', 
                            'itemName': '四库一平台', 
                            'nodeId': '2', 
                            'nodeName': '建筑-业绩'
                        }, 
                        {
                            'itemId': '1', 
                            'itemName': '四库一平台', 
                            'nodeId': '4', 
                            'nodeName': '建筑-不良行为' 
                        }
                    ], 
                    'remark': null,
                    'nodeid':'skypt',
                }, 
                {
                    'itemId': '10', 
                    'itemName': '法律诉讼', 
                    'nodeId': '40', 
                    'nodeName': '法律诉讼',
                    'remark': null,
                    'nodeid':'flss',
                },    
                {
                    'itemId': '6', 
                    'itemName': '拖欠农民工工资', 
                    'nodeId': '39', 
                    'nodeName': '拖欠农民工工资',
                    'remark': null,
                    'nodeid':'tqnmggz',
                }
            ],
        };
    },
    computed: {

    },
    watch: {
        
    },
    methods: {
        componentName(id){
            return this.componentsNameById[id] 
        },
        go(item){
            let id = ""
            id = item.nodeId || item.itemNodeRecords[0].nodeId;

            let myHref = this.isHavingPower ? `#${id}` : `#guide`;

            // window.location.href = myHref;
            document.getElementById(`${id}`).scrollIntoView({ block: 'center' });
        },
        pushValidNames(name){
            this.validNames = [...new Set([...this.validNames,name])]; 
        },
        isValid(item){
            const that = this;

            let res = false;

            res = that.validNames.includes(item.nodeName || item.itemName); 

            return res;
        },
        btnDisabled(item){
            return this.isHavingPower ? !this.isValid(item) : false
        },
        getJiaotongComId(){
            const that = this;

            that.$ajax({
                type:"get",
                url: `${that.$store.state.api.searchUrl}/searchjiaotong/jiaotong/searchbycorpName`,
                data: {
                    corpName: that.company
                },
                callback:function(data, res){
                    if(!data.id){
                        that.jiaotongComId =  that.corpType = ""
                    }else{
                        that.jiaotongComId = data.id;
                        that.corpType = data.corpType;
                        that.pushValidNames("全国公路建设市场信用信息管理系统")
                    }
                }
            })
        },
        // 抓取数据的平台无法继续抓取
        getShuiliComId(){
            const that = this;

            that.$ajax({
                type:"get",
                url: `${that.$store.state.api.searchUrl}/searchshuili/shuili/getqiyeid`,
                data: {
                    corpName: that.company
                },
                callback:function(data, res){
                    if(!data){
                        that.shuiliComId = ""
                    }else{
                        that.shuiliComId = data;
                        that.pushValidNames("全国水利建设市场信用信息平台")
                    }
                }
            });
        }
    },
    mounted () {
        if(this.isLogin){
            this.getJiaotongComId();
            // this.getShuiliComId();
        }
    },
};
</script>

<style lang="scss" scoped>
@import '@css/var.scss';
    .riks-query {
        .tags {
            display: flex;
            flex-wrap: wrap;
            margin-top: 10px;

            .info-type {
                margin-right: 10px;
                margin-top: 5px;
                margin-bottom: 5px;

                ::v-deep{
                    .el-button{
                        padding: 5px 8px;
                    }

                    .is-disabled{
                        color: #606266;
                    }
                }
            }
        }

        .riks-main {
            .item {
                margin-top: 29px;
                h3 {
                    margin-bottom: 13px;
                }
            }
        }

        .guide {
            margin-top: 20px;
        }
        .base-bot{
            margin-top: 20px;
        }
        
    }
</style>